package com.itlaoqi.springcloud.memberserviceopenfeign.controller;

import com.itlaoqi.springcloud.memberserviceopenfeign.client.BookService;
import com.itlaoqi.springcloud.memberserviceopenfeign.entity.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MemberController {
    @Resource
    BookService bookService;
    @GetMapping("/borrow")
    @ResponseBody
    public String borrow(String sn){
        Book book = bookService.findBySn(sn);
        return book.getName() + ":" + book.getDesc() + "图书借阅成功";
    }

    @GetMapping("/c")
    @ResponseBody
    public String compensate(){
        Book book = new Book();
        book.setName("赔偿图书");
        book.setSn("5555");
        String result = bookService.createBook(book);
        return result;
    }

    @GetMapping("/s")
    @ResponseBody
    public List<Book> search(){
        Map param = new HashMap();
        param.put("sn", "1111");
        param.put("name", "x");
        List<Book> list = bookService.search(param);
        return list;
    }
}
